package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.esm.dao.SelectUidDao;
import com.esm.daoimpl.SelectUidDaoimpl;
import com.esm.service.UpdateRecordService;
import com.esm.serviceimpl.UpdateRecordServiceImpl;

import net.sf.json.JSONObject;
/**
 * 更改请假记录 Controller
 * @author 康少
 *
 * 2017年1月5日
 */
public class UpdateLeavelController extends HttpServlet{
	UpdateRecordService update = new UpdateRecordServiceImpl();
	SelectUidDao seleuid = new SelectUidDaoimpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int att_id = Integer.parseInt(req.getParameter("att_id"));
		String uname = req.getParameter("uname");
		int uid = seleuid.getUidByUname(uname);
		String state = req.getParameter("state");
		String time = req.getParameter("time");
		String date = req.getParameter("date");
		String remark = req.getParameter("remark");
		boolean flag = update.updateLeavel(att_id, uid, uname, state, time, date, remark);
		JSONObject j = new JSONObject();
		j.put("flag", flag);
		PrintWriter pw = resp.getWriter();
		pw.write(j.toString());
		pw.flush();
		pw.close();
		
	}
}
